﻿using GenerateWeixinCert.Lib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GenerateWeixinCert
{
    class Program
    {
        static void Main(string[] args)
        {
            var pemkey = Getpublickey();
            Console.WriteLine(pemkey);

            Console.ReadKey();
        }

        private static string Getpublickey()
        {
            string url = "https://fraud.mch.weixin.qq.com/risk/getpublickey";
            WxPayData inputObj = new WxPayData();
            inputObj.SetValue("mch_id", "10010746");//商户号
            inputObj.SetValue("nonce_str", Guid.NewGuid().ToString().Replace("-", ""));//随机字符串
            inputObj.SetValue("sign_type", WxPayData.SIGN_TYPE_HMAC_SHA256);
            inputObj.SetValue("sign", inputObj.MakeSign().ToUpper());//签名
            string xml = inputObj.ToXml();
            string response = HttpService.Post(xml, url, true, 10);//调用HTTP通信接口以提交数据到API

            return response;
            //WxPayData result = new WxPayData();
            //var res = result.FromXml(response);
            //////公钥获取后存储为 pub.pem
            //return res.ToString();
        }
    }
}
